home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / udpdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  2KB  |  105 lines

  1. /* UDP packet tracing
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. /* Mods by PA0GRI */
  5. #include <stdio.h>
  6. #include "global.h"
  7. #include "config.h"
  8. #include "mbuf.h"
  9. #include "netuser.h"
  10. #include "internet.h"
  11. #include "udp.h"
  12. #include "ip.h"
  13. #include "socket.h"
  14. #include "trace.h"
  15.  
  16. #ifdef MONITOR
  17. void rwho_dump __ARGS((FILE *fp,struct mbuf **bpp,int mon));
  18. #else
  19. void rwho_dump __ARGS((FILE *fp,struct mbuf **bpp));
  20. #endif
  21.  
  22. /* Dump a UDP header */
  23. void
  24. #ifdef MONITOR
  25. udp_dump(fp,bpp,source,dest,check,mon)
  26. #else
  27. udp_dump(fp,bpp,source,dest,check)
  28. #endif
  29. FILE *fp;
  30. struct mbuf **bpp;
  31. int32 source,dest;
  32. int check;        /* If 0, bypass checksum verify */
  33. #ifdef MONITOR
  34. int mon;
  35. #endif
  36. {
  37.     struct udp udp;
  38.     struct pseudo_header ph;
  39.     int16 csum;
  40.  
  41.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  42.         return;
  43.  
  44. #ifdef MONITOR
  45.     if (!mon)
  46. #endif
  47.     fprintf(fp,"UDP:");
  48.  
  49.     /* Compute checksum */
  50.     ph.source = source;
  51.     ph.dest = dest;
  52.     ph.protocol = UDP_PTCL;
  53.     ph.length = len_p(*bpp);
  54.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  55.         check = 0;    /* No checksum error */
  56.  
  57.     ntohudp(&udp,bpp);
  58.  
  59. #ifdef MONITOR
  60.     if (!mon)
  61. #endif
  62.     fprintf(fp," len %u ",udp.length);
  63.     fprintf(fp,"%u->%u",udp.source,udp.dest);
  64. #ifdef MONITOR
  65.     if (!mon)
  66. #endif
  67.     if(udp.length > UDPHDR)
  68.         fprintf(fp," Data %u",udp.length - UDPHDR);
  69.     if(udp.checksum == 0)
  70.         check = 0;
  71.     if(check)
  72.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  73.  
  74. #ifdef MONITOR
  75.     if (!mon)
  76. #endif
  77.     fprintf(fp,"\n");
  78.  
  79.     switch(udp.dest){
  80. #ifdef RIP
  81.     case IPPORT_RIP:
  82. #ifdef MONITOR
  83.         rip_dump(fp,bpp,mon);
  84. #else
  85.         rip_dump(fp,bpp);
  86. #endif
  87.         break;
  88. #endif
  89.     case IPPORT_RWHO:
  90. #ifdef MONITOR
  91.         rwho_dump(fp,bpp,mon);
  92. #else
  93.         rwho_dump(fp,bpp);
  94. #endif
  95.         break;
  96. #ifdef MONITOR
  97.         default:
  98.         if (mon)
  99.             fprintf(fp, "\n");
  100. #endif
  101.     }
  102.  
  103. }
  104.  
  105.